Xbasic

BITMAP Function

Syntax

V BITMAP(C bitmap_name,N XPos,N YPos[,N Width,N Height[,C bitmap_style]])

Arguments

bitmap_nameCharacter

The name of the bitmap.

XPosNumeric

The horizontal coordinate of the bitmap's upper left corner.

YPosNumeric

The vertical coordinate of the bitmap's upper left corner.

WidthNumeric

The width of the bitmap is created dynamically. The width of the bitmap.

HeightNumeric

The height of the bitmap is created dynamically. The height of the bitmap.

bitmap_styleCharacter

Default = "TRANPARENT". The following values are possible. Combine values in a comma delimited list, as in: " value1,value2,value3 ". ABSOLUTE,BESTFIT,STRETCH,TILE combined optionally with OPAQUE combined optionally with BLACKONWHITE,COLORONCOLOR,HALFTONE,WHITEONWHITE.

"TRANSPARENT"

Scales the bitmap before sending it to the printer.

"ABSOLUTE"

Do not stretch or crop the image.

"BEST-FIT"

Scale the image so that either height or width fits exactly, and the other dimension is cropped to fit.

"STRETCH"

Scale, but do not distort the image to fit the space.

"TILE"

If the image is smaller than the space, tile the image as necessary to fill the space.

"HALFTONE"

Best quality for photos. Does sampling instead of eliminating pixels (produces an antialiased image).

"COLORONCOLOR"

Do not favor any color over another on the scale.

"WHITEONBLACK"

Preserve white pixels at the expense of black pixels.

"BLACKONWHITE"

Preserve black pixels at the expense of white pixels.

"ROTATE"

Rotate image 180 degrees.

"ROTATE-LEFT"

Rotate image 90 degrees left.

"ROTATE-RIGHT"

Rotate image 90 degrees right.

Description

BITMAP() draws a bitmap in memory.

Example

Get the original color image, then extract the color data and the alpha channel data.

png_data = file.to_blob("c:\documents\Xbasic Reference\Images\toucan.png")
rgb_data = png_to_bitmap(png_data, "R")
trans_data = png_to_bitmap(png_data, "A")

Create two bitmaps from the color data and the alpha channel data.

ui_bitmap_load("rgb", rgb_data)
ui_bitmap_load("trans", trans_data)

Calculate the positions of the three images.

pixsize = ui_bitmap_info_get(rgb_data, "w,h")
xpix = val( word(pixsize, 1, ",") )
ypix = val( word(pixsize, 2, ",") )
xperin = ui_info(4)
yperin = ui_info(5)
width = xpix/xperin
height = ypix/yperin

Combine the three images.

ui_bitmap_create("combine", width, height)
stone_data = file.to_blob("C:\WINDOWS\Greenstone.bmp")
ui_bitmap_load("Stone", stone_data)
ui_bitmap_draw("combine", <<%code%
bitmap("stone", 0, 0)
bitmap_alpha("rgb", 0, 0, "trans")
%code%)

put description here

images/GR_bitmap_alpha.gif
ui_dlg_box("image", <<%dlg% {image=rgb} {image=trans} {image=combine}
%dlg%)

To print a photo.

bitmap("all",0,0,width,height,"BESTFIT,HALFTONE")

The following script demonstrates a thumbnail generator that uses these features.

filename = ui_get_file("Select Image File", "(*.jpg")
width = 41/96
height = 55/96
imagebits = file.to_blob(filename)
bmpbits = jpeg_to_bitmap(imagebits)
ui_bitmap_load("selected_picture", bmpbits)
ui_bitmap_create("thumbnail", width, height)
ui_bitmap_draw("thumbnail",<<%code%
bitmap("selected_picture",0,0,width,height,"best-fit,opaque,rotate-right,halftone")
'bitmap("selected_picture",0,0,1,1,"best-fit,rotate-right,halftone")
%code%)
thumbbits = ui_bitmap_save("thumbnail")
dlg_image_format = "Jpeg Image Thumbnails;Image|"
dlg_image_desc1 = "Quality|"
dlg_image_desc2 = "Size|"
for quality = 0 to 10
    jbits = bitmap_to_jpeg(thumbbits,quality*10)
    imagename = "Thumb_"+quality*10
    ui_bitmap_load(imagename, jpeg_to_bitmap(jbits) )
    dlg_image_format = dlg_image_format + "|{image="+imagename+"}"
    dlg_image_desc1 = dlg_image_desc1 + "| "+(quality*10)
    dlg_image_desc2 = dlg_image_desc2 + "| "+jbits.size()
next
ui_dlg_box("",dlg_image_format+";"+dlg_image_desc1+";"+dlg_image_desc2+";")

This code reads a JPEG image, rotates it by 90 degrees, then saves it.

ui_bitmap_load("input", bb)
ui_bitmap_draw("input",<<%code%
w = bitmap_width("input")
h = bitmap_height("input")
%code%)
ui_bitmap_create("output", h, w)
ui_bitmap_draw("output",<<%code%
bitmap("input",0,0,h,w,"ROTATE-LEFT,HALFTONE")
bb = ui_bitmap_save("output")
%code%)
file.From_blob("c:\output.jpg", bb)

Limitations

BITMAP() is only used in the Code section of UI_BITMAP_DRAW() and UI_SCREEN_DRAW().

See Also